package com.leetcode.algorithm.y22.m07;

import java.util.ArrayList;
import java.util.List;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 144. 二叉树的前序遍历
 * 
 * https://leetcode.cn/problems/binary-tree-preorder-traversal/
 * 
 * @author jie.deng
 *
 */
public class Question0144Solution01 {

	public List<Integer> preorderTraversal(TreeNode root) {
		List<Integer> list = new ArrayList<Integer>();
		preorderTraversal(root, list);
		return list;
	}

	private void preorderTraversal(TreeNode cur, List<Integer> list) {
		if (cur == null) {
			return;
		}
		list.add(cur.val);
		preorderTraversal(cur.left, list);
		preorderTraversal(cur.right, list);
	}

}